package classwork.demo3;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

public class day1 {
    public static void main(String[] args) throws Exception {
        Class.forName("com.mysql.jdbc.Driver");

        String url="jdbc:mysql://localhost:3306/db2";
        String user="root";
        String pwd="root";

        Connection connection = DriverManager.getConnection(url, user, pwd);

        if(connection == null){
            System.out.println("连接失败");
        }else {
            System.out.println("连接成功");

            Statement statement = connection.createStatement();

            String sql="INSERT INTO stu VALUES(2,'张三','123456')";

            if(statement.executeUpdate(sql)>=1){
                System.out.println("插入成功！");
            }else{
                System.out.println("插入失败！");
            }
            connection.close();
        }
    }
}
